package com.example.replacebooks.controller;


import com.example.replacebooks.common.Result;
import com.example.replacebooks.entity.Bookinfo;
import com.example.replacebooks.entity.Params;
import com.example.replacebooks.entity.User;
import com.example.replacebooks.service.BookinfoService;
import com.example.replacebooks.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 书籍信息表 前端控制器
 * </p>
 *
 * @author replacebooks
 * @since 2024-12-15
 */
@RestController
@RequestMapping("/bookinfo")
public class BookinfoController {
    @Resource
    private BookinfoService bookinfoService;

    @PostMapping("/add")
    public Result add(@RequestBody Bookinfo bookinfo){
        bookinfoService.add(bookinfo);
        return Result.success();
    }

    @PostMapping("/savestatu")
    public Result savestatu(@RequestBody Bookinfo bookinfo){
        bookinfoService.savestatu(bookinfo);
        return Result.success();
    }

    @GetMapping("/{bookid}")
    public Result findByBookid(@PathVariable Integer bookid){
        Bookinfo list = bookinfoService.findByBookid(bookid);
        return Result.success(list);
    }

    @PostMapping("/{classid}")
    public Result findByClassid(@PathVariable Integer classid){
        List<Bookinfo> list = bookinfoService.findByClassid(classid);
        return Result.success(list);
    }

    @GetMapping("/search")
    public Result findBySearch(Params params){
        PageInfo<Bookinfo> info = bookinfoService.findBySearch(params);
        return Result.success(info);
    }

    @GetMapping("/myaddbook")
    public Result myaddbook(Params params){
        PageInfo<Bookinfo> info = bookinfoService.myaddbook(params);
        return Result.success(info);
    }

    @GetMapping("/statusearch")
    public Result findByStaueSearch(Params params){
        PageInfo<Bookinfo> info = bookinfoService.findByStatuSearch(params);
        return Result.success(info);
    }
    @DeleteMapping("/{bookid}")
    public Result delete(@PathVariable Integer bookid){
        bookinfoService.delete(bookid);
        return Result.success();
    }
}
